package org.example.encoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.embedded.EmbeddedChannel;

/**
 * @author hh
 * @since 2024/11/17
 */
public class TestInteger2ByteEncoder {
    public static void main(String[] args) {
        ChannelInitializer i = new ChannelInitializer<EmbeddedChannel>() {
            @Override
            protected void initChannel(EmbeddedChannel ch) throws Exception {
                ch.pipeline().addLast(new Integer2ByteEncoder());
            }
        };

        EmbeddedChannel channel = new EmbeddedChannel(i);
        for (int j = 0; j < 200; j++) {
            channel.write(j);// 向通道写入整数
        }
        channel.flush();
        // 取出通道的出站数据包
        ByteBuf buf = channel.readOutbound();
        while (buf != null) {
            System.out.println("o = " + buf.readInt());
            buf = channel.readOutbound();
        }
    }
}
